<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/login.css" />
		<link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_425307_aq150n9pewcj714i.css" />
		<title>忘记密码</title>
		<script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<!--<div id="header">

		</div>-->
		<div class="weui-cells weui-cells_form" style="margin-top: 0;">
			<div class="weui-cell">
				<div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
				<div class="weui-cell__bd">
					<input class="weui-input phoneNumber" type="number" pattern="[0-9]*" placeholder="请输入手机号码">
				</div>
			</div>
			<div class="weui-cell ">
				<div class="weui-cell__hd">
					<label class="weui-label">验证码</label>
				</div>
				<div class="weui-cell__bd">
					<input class="weui-input code" type="tel" placeholder="请输入验证码">
				</div>
			</div>
		</div>
		<div class="forgetPassword">
			<a href="javascript:;" class="weui-btn weui-btn_mini sendCode" style="border: 1px solid #28C81E;">发送验证码</a>
		</div>
		<div class="demos-content-padded">
			<a href="javascript:;" class="weui-btn weui-btn_primary confirm">确定</a>
		</div>
	</body>
	<script type="text/javascript">
		$(document).ready(function() {
//			$("#header").load('../common/header.html', function() {
//				$(".header-title").css("background", "#fff")
//				$(".header-title span").html("忘记密码")
//				$("#header .iconfont").css("display", "inline-block")
//				$(".header-title .left").on("click", function() {
//					history.back()
//				})
//			});
			baseConfig.historyBack()
			//获取验证码的判断
			$(".sendCode").on("click", function() {
				var phoneNumber = $(".phoneNumber").val()
				//var code = $(".code").val()
				if(!phoneNumber) {
					$.toptip('手机号不能为空', 1200, 'error');
				} else {
					var reg = new RegExp(/^1[34578]\d{9}$/);
					if(!reg.test(phoneNumber) || phoneNumber.length != 11) {
						$.toptip('请输入正确的手机号', 1200, 'error');
					} else {
						$.ajax({
							type: "get",
							url: baseConfig.localHttp + "weChatApi/login/getVCode",
							async: true,
							data: {
								phone: phoneNumber
							},
							headers: {
								'Content-Type': 'application/x-www-form-urlencoded'
							},
							success: function(data) {
								console.log(data)
								if(data.code == 100) {
									var wait = 60;
									$(".sendCode").css({"pointer-events":"none","color":"#444","border-color":"#444"})
									$.toast("验证码发送成功");
									var waitTime = setInterval(function(){
										$(".sendCode").html("重新发送"+"("+wait+")")
										wait--
										if(wait<0){
											$(".sendCode").html("发送验证码")
											$(".sendCode").css({"pointer-events":"auto","color":"#28c81e","border-color":"#28c81e"})				
											clearInterval(waitTime)
										}
									},1000)
								} else {
									
									$.toptip(data.content, 1200, 'error');
								}
							}
						});						
					}
				}
			})
			//点击确认
			$(".confirm").on("click",function(){
				var phoneNumber = $(".phoneNumber").val();
				var code = $(".code").val();
				if(!phoneNumber) {
					$.toptip('手机号不能为空', 1200, 'error');
				} else {
					var reg = new RegExp(/^1[34578]\d{9}$/);
					if(!reg.test(phoneNumber) || phoneNumber.length != 11) {
						$.toptip('请输入正确的手机号', 1200, 'error');
					} else {
						if(!code){
							$.toptip('请输入验证码', 1200, 'error');
						}else{
							$.ajax({
								type:"post",
								url:baseConfig.localHttp+"weChatApi/login/confirmCode",
								headers: {
									'Content-Type': 'application/x-www-form-urlencoded'
								},
								data:{
									phone:phoneNumber,
									code:code
								},
								success:function(data){
									console.log(data)
									if(data.code==100){
										$.toast("验证成功",function(){
											window.location.href = "setNewpassword.html?phone="+phoneNumber
										});
									}else{
										$.toptip(data.content, 1200, 'error');
									}
								},
								error:function(data){
									
								}
							});
						}
					}
				}	
			})
			
			
		})
	</script>

</html>